/*
仿照PizzaStore案例，将手机案例构造为抽象工厂模式。
 */

package demo2.assignment2;

import demo2.assignment2.phone.PhoneType;
import demo2.assignment2.phone.brand.PhoneBrand;
import demo2.assignment2.phone.color.PhoneColor;

import java.util.Scanner;

/**
 * @author Leon(赵亮)
 * @version 1.0
 * 8 Sep 2021
 * the main entrance of phone abstract factory demo
 * input the first number to select a brand and
 * input the second number to select a color,
 * then you will get a phone you want it to be.
 */
public class PhoneSellMan {

    public static void main(String[] args) {
        System.out.println("Hi Sir/Ms, what kind of phone would you like to buy?\n" +
                "Please tell me the number you want:\n" +
                "1,iPhone 12 Pro Max\t\t2,Samsung Galaxy s21,\t\t3,Huawei Mate 80");
        Scanner s = new Scanner(System.in);
        String brand = getTypeOfInput(s.nextInt());
        System.out.println("And second, what color do you want?\n" +
                "Please tell me the number you want:\n" +
                "1,Blue\t\t2,Purple,\t\t3,White\n4,Black");

        String color = getColorOfInput(s.nextInt());

        PhoneFactoryProducer factoryProducer = new PhoneFactoryProducer();

        PhoneAbstractFactory brandFactory = factoryProducer.getPhoneFactory("Brand");

        PhoneBrand phoneBrand = brandFactory.getPhoneBrand(brand);

        PhoneAbstractFactory colorFactory = factoryProducer.getPhoneFactory("Color");
        PhoneColor phoneColor = colorFactory.getPhoneColor(color);

        System.err.println("Sir/Ms, this is your " + phoneColor.color() + " " + phoneBrand.brand());
    }

    public static String getTypeOfInput(int type) {
        switch (type) {
            case 1:
                return PhoneType.Brand.iPhone;
            case 2:
                return PhoneType.Brand.samsung;
            case 3:
                return PhoneType.Brand.huawei;
        }
        return "";
    }

    public static String getColorOfInput(int type) {
        switch (type) {
            case 1:
                return PhoneType.Color.blue;
            case 2:
                return PhoneType.Color.purple;
            case 3:
                return PhoneType.Color.white;
            case 4:
                return PhoneType.Color.black;
        }
        return "";
    }
}
